import api from '@MODULES/common/api'
import store from 'store'
import {
    Modal
} from 'antd-mobile';

const alert = Modal.alert;

const common = {
    // 获取用户个人信息
    userInfoUpData: (success) => {
        api.personDes({
            success: (data) => {
                store.set('user', data.user)
                if (success) {
                    success(data.user)
                }
            }
        })
    },
    // 处理输入后页面不会回调
    inputBlur: () => {
        let windowFocusHeight = window.innerHeight
        // if (windowHeight == windowFocusHeight) {
        //     return
        // }
        // console.log(windowHeight + '--' + windowFocusHeight);
        console.log('修复');
        let currentPosition;
        let speed = 1; //页面滚动距离
        currentPosition = document.documentElement.scrollTop || document.body.scrollTop;
        currentPosition -= speed;
        window.scrollTo(0, currentPosition); //页面向上滚动
        currentPosition += speed; //speed变量
    },
    // 默认头像
    showFace: (src) => {
        return src || require('@MODULES/common/img/static/deFace.jpeg')
    },
    // 默认图片
    showImg: (src) => {
        return src || require('@MODULES/common/img/static/contentDefault.png')
    },
    // 判断是否登录
    userIsLogin: (callBack) => {
        if (store.get('user')) {
            if (callBack) {
                callBack()
            }
        } else {
            alert('很抱歉', '您还未登录', [{
                    text: '取消',
                    onPress: () => console.log('cancel'),
                    style: 'default'
                },
                {
                    text: '去登录',
                    onPress: () => {
                        window.location.href = '/login/goBack'
                    }
                },
            ])
        }
    }
}
export default common;
